package com.mobiftpcms.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="user_user_task")
public class UserUserTask extends BaseObject implements Serializable {
	private Long id;
	
	private Long userId;
	
	private Long taskId;
	
	private Set<UserTaskParam> userTaskParams;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name="user_id")
	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	@Column(name="task_id")
	public Long getTaskId() {
		return taskId;
	}

	public void setTaskId(Long taskId) {
		this.taskId = taskId;
	}	

	@Override
	public String toString() {
		return getTaskId() + " " + getUserId();
	}

	@OneToMany(fetch = FetchType.EAGER)
    @JoinTable(
            name = "user_user_task_params",
            joinColumns = { @JoinColumn(name = "user_user_task_id") },
            inverseJoinColumns = @JoinColumn( name="task_param_id")
    )
	public Set<UserTaskParam> getUserTaskParams() {
		return userTaskParams;
	}

	public void setUserTaskParams(Set<UserTaskParam> userTaskParams) {
		this.userTaskParams = userTaskParams;
	}

	@Override
	public boolean equals(Object o) {
		if(o != null) {
			if(o instanceof UserUserTask) {
				UserUserTask uut = (UserUserTask) o;
				return uut.getTaskId().equals(getTaskId()) && uut.getUserId().equals(getUserId());
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		return getTaskId().intValue() + getUserId().intValue();
	}
	
	
}
